Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON as an option for log output #1654

Merged
merged 4 commits into from
Jul 30, 2019

Conversation

carthewd
Copy link
Contributor

This enhancement is quite useful for my team so I took a crack at adding it. Adds an option to output logs as JSON via --log-json (e.g., velero server --log-json)

Fixes #598

Signed-off-by: Donovan Carthew donovan.carthew@gmail.com

Copy link
Contributor

@nrb nrb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I've given it a quick skim, and have one comment

pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
@nrb nrb added the Enhancement/User End-User Enhancement to Velero label Jul 11, 2019
@skriss
Copy link
Member

skriss commented Jul 15, 2019

thanks for the PR @carthewd! I'm wondering if it would make more sense to add a flag like --log-format, and then allow text (the current) or json as options. It makes it easier to add a third option later - otherwise you end up with a flag per option where only one can be true. What do others think?

@prydonius
Copy link
Contributor

+1 looks like logrus only supports text and json outside of external formatters, but I agree that a --log-format option makes more sense and will make this easy to extend in the future.

pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/cmd/cli/restic/server.go Outdated Show resolved Hide resolved
pkg/cmd/server/server.go Outdated Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Jul 19, 2019

@carthewd thanks for the update! there are some more changes that I'd like to see made, but you're under no obligation to keep refining - I'm happy to make the changes myself (you'll still be tagged on the commit and changelog). Or, if you do have the appetite, I can provide another round of comments. Totally up to you - just let me know!

@carthewd
Copy link
Contributor Author

Thanks @skriss - I really appreciate the feedback! I’m quite happy to keep refining this and get it right if it’s on the right track so feel free to add more comments

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, added comments around the core change I'd like to make - some of the other code will have to update as well to compile once these changes are made, but hopefully those become clear.

The other thing is I don't think we need to add the loops in all of our tests to exercise both log formats. Let's add a single test in pkg/util/logging that sets up a logger using both formats, and validates that the output is what we expect, and then we can remove the loops in the other tests.

changelogs/unreleased/598-carthewd Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Jul 22, 2019

Once you've made the updates, make sure to run make update locally to properly format all of the go imports.

Signed-off-by: Donovan Carthew <donovan.carthew@gmail.com>
Signed-off-by: Donovan Carthew <donovan.carthew@gmail.com>
Signed-off-by: Donovan Carthew <donovan.carthew@gmail.com>
Copy link
Contributor

@carlisia carlisia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lgtm, is it missing any more review to be addressed?

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @carthewd, just 2 minor things then LGTM. Thanks for the updates!

pkg/util/logging/format_flag.go Show resolved Hide resolved
pkg/util/logging/default_logger.go Outdated Show resolved Hide resolved
Signed-off-by: Donovan Carthew <donovan.carthew@gmail.com>
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@carlisia carlisia merged commit 22eca22 into vmware-tanzu:master Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement/User End-User Enhancement to Velero
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants